﻿//https://leetcode.cn/problems/department-top-three-salaries/?envType=problem-list-v2&envId=database

# Write your MySQL query statement below

select
d.Name AS 'Department', e1.Name AS 'Employee', e1.Salary
from
Employee e1
join
Department d on e1.departmentId = d.Id
where
3 > (select
    count(distinct e2.Salary)
    from
    Employee e2
    where
    e2.Salary > e1.Salary
    and e1.departmentId = e2.departmentId
    )
    ;